package cn.tedu._07springaop.egaop1;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * 切面类
 */
@Aspect
@Component
public class OrderCheckAspect {
    @Before(value = "execution(public void cn.tedu._07springaop.egaop1.OrderServiceImpl.*(..))")
    public void check(JoinPoint joinPoint){
        /**
         * 1. joinPoint.getArgs()获取参数
         * 2. 终端打印 得到Object[]数组
         * 3. 获取单个元素(强转)
         *    Integer number = (Integer) joinPoint.getArgs()[0];
         */
        Integer number = (Integer) joinPoint.getArgs()[0];
        if (number < 0) {
            throw new IllegalArgumentException("订单数量不能小于0");
        }
    }
}
